package com.gelingqin.es.springbootdemo.controller;

import java.util.Map;

import com.gelingqin.es.springbootdemo.service.ElasticsearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * 索引生命周期管理
 * @author 86133
 *
 */


@RestController
@RequestMapping("/iml/")
public class IlmController {
	
	@Autowired
	private ElasticsearchService elasticsearchService;
	
	/**
	 * 生命周期策略列表
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("listAll")
	public Map listAll() {
		return elasticsearchService.performRequest("GET","/_ilm/policy",null,Map.class);
	}

	/**
	 * 创建生命周期策略
	 * 示例参数：param/iml-create
	 * @param map
	 * @return
	 */
	@RequestMapping("create")
	public Map create(@RequestBody Map<String,Object> map){
		String id=(String)map.get("id");
		return elasticsearchService.performRequest("PUT","/_ilm/policy/"+id,map.get("param"),Map.class);

	}


}
